<template>
    <div class="main-wrapper">
        <div class="uc-box uc-main-box">
            <div class="uc-content-box order-list-box">
                <div class="box-hd">
                    <h1 class="title">我的订单</h1>
                    <div class="more clearfix">
                        <div class="search-form clearfix">
                            <input type="search" name="keywords" autocomplete="off" placeholder="输入商品名称、订单号" class="search-text" v-model="params.keyword" />
                            <div class="search-btn" @click="getData">
                                <i class="icon-sousuo iconfont"></i>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="box-bd">
                    <div>
                        <ul class="order-list">
                            <item-pay v-for="(item,index) in orderPay" :key="item.orderId" :orderInfo="item"></item-pay>
                            <item-finish v-for="(item,index) in orderFinish" :key="item.orderId" :orderInfo="item"></item-finish>
                        </ul>
                    </div>
                </div>
            </div>
            <div class="wrapper">
                <el-pagination background layout="prev, pager, next" :total="totalNums" class="pagination" style="display: flex;
                    justify-content: center;" :page-size="params.pageSize" @current-change="handleCurrentChange"></el-pagination>
            </div>
        </div>
    </div>
</template>

<script>
import { mapState } from "vuex";
import ItemFinish from "@/pages/Userspace/Main/MyTrade/ItemFinish";
import ItemPay from "@/pages/Userspace/Main/MyTrade/ItemPay";

export default {
    data() {
        return {
            params: {
                keyword: "",
                pageNo: 1,
                pageSize: 5,
            },
        };
    },
    components: {
        ItemFinish,
        ItemPay,
    },
    methods: {
        async getData() {
            try {
                await this.$store.dispatch(
                    "user/getUserOrderList",
                    this.params
                );
            } catch (error) {
                this.$message.error(error);
            }
        },
        handleCurrentChange(val){
            this.params.pageNo = val;
            this.getData();
        }
    },
    mounted() {
        this.getData();
        // 在总线上绑定事件
        this.$bus.$on("updataOrderList",this.getData)
    },
    beforeDestroy(){
        this.$bus.$off("updataOrderList")
    },
    computed: {
        ...mapState("user", ["totalNums", "orderList"]),
        // 分割出待支付订单和其它订单
        orderPay() {
            return this.orderList.filter((item) => item.status === 2);
        },
        orderFinish() {
            return this.orderList.filter((item) => item.status !== 2);
        },
    },
};
</script>

<style lang="less" scoped>
.main-wrapper {
    -webkit-text-size-adjust: 100%;
    font: 14px/1.5 Helvetica Neue, Helvetica, Arial, Microsoft Yahei,
        Hiragino Sans GB, Heiti SC, WenQuanYi Micro Hei, sans-serif;
    color: #333;
    float: left;
    margin-left: 14px;
    min-height: 1px;
    width: 978px;

    .uc-box {
        color: #333;
        padding: 36px 0;
        background-color: rgba(255, 255, 255, 0.8);

        .uc-content-box {
            color: #333;
            margin: 0 48px;

            .box-hd:first-child {
                margin-bottom: 30px;
            }

            .box-hd {
                color: #333;

                .title {
                    margin: 0;
                    font-size: 30px;
                    font-weight: 400;
                    line-height: 68px;
                    color: #757575;
                }

                .more {
                    color: #333;
                    border-bottom: 0;

                    .filter-list {
                        color: #333;
                        float: left;
                        margin: 0;
                        padding: 18px 0;
                        list-style-type: none;
                        font-size: 16px;
                        line-height: 1.25;

                        li {
                            list-style-type: none;
                            font-size: 16px;
                            line-height: 1.25;
                            float: left;
                            padding: 0 20px;
                            border-left: 1px solid #e0e0e0;
                            color: #757575;

                            a {
                                list-style-type: none;
                                font-size: 16px;
                                line-height: 1.25;
                                background-color: rgba(0, 0, 0, 0);
                                text-decoration: none;
                                color: #757575;
                                cursor: pointer;
                            }
                        }

                        .active {
                            a {
                                color: #ff6700;
                            }
                        }

                        .first {
                            list-style-type: none;
                            font-size: 16px;
                            line-height: 1.25;
                            float: left;
                            padding: 0 20px;
                            padding-left: 0;
                            border-left: 0;
                        }
                    }

                    .search-form {
                        color: #333;
                        float: right;
                        position: relative;
                        width: 262px;
                        height: 40px;
                        margin-top: 8px;

                        label {
                            color: #333;
                            display: none !important;
                        }

                        input[type="search"] {
                            -webkit-text-size-adjust: 100%;
                            font: inherit;
                            margin: 0;
                            -webkit-appearance: textfield;
                            box-sizing: content-box;
                            right: 41px;
                            z-index: 1;
                            width: 189px;
                            height: 42px;
                            padding: 0 15px;
                            font-size: 12px;
                            line-height: 40px;
                            color: #757575;
                            position: absolute;
                            top: 0;
                            border: 1px solid #e0e0e0;
                            outline: 0;
                            transition: all 0.2s;
                        }

                        .search-btn {
                            -webkit-text-size-adjust: 100%;
                            font: inherit;
                            margin: 0;
                            font-family: iconfont !important;
                            font-style: normal;
                            -webkit-font-smoothing: antialiased;
                            -webkit-text-stroke-width: 0.2px;
                            -webkit-appearance: button;
                            cursor: pointer;
                            position: absolute;
                            top: 0;
                            border: 1px solid #e0e0e0;
                            outline: 0;
                            transition: all 0.2s;
                            right: 0;
                            z-index: 2;
                            width: 42px;
                            height: 42px;
                            font-size: 0px;
                            line-height: 42px;
                            background: #fff;
                            color: #616161;

                            vertical-align: middle;
                            text-align: center;

                            .icon-sousuo {
                                font-size: 24px;
                                transition: color 0.3s ease;
                            }

                            .icon-sousuo:hover {
                                color: #ff6700;
                            }
                        }
                    }
                }

                div {
                    .order-list {
                        color: #333;
                        margin: 0;
                        padding: 10px 0;
                        list-style-type: none;
                    }
                }
            }

            .wrapper {
                background-color: white;
                width: 1200px;
                margin: 0 auto;
                padding-bottom: 30px;
            }
        }
    }
}
</style>